﻿Public Partial Class Palpite
    Inherits System.Web.UI.Page

    Private IdGP As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Util.EhVazioNull(Session("IdUsuario")) Then
            Response.Redirect("Login.aspx")
        End If
        IdGP = Request.QueryString("IdGP")
        VerificaHoraLimite()
    End Sub

    Protected Sub btnGravar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGravar.Click
        Dim ta As DataSet1TableAdapters.PalpiteTableAdapter = New DataSet1TableAdapters.PalpiteTableAdapter
        Dim table As DataSet1.PalpiteDataTable = New DataSet1.PalpiteDataTable
        Dim row As DataSet1.PalpiteRow = table.NewRow()
        row.IdUsuario = Session("IdUsuario")
        row.IdGP = IdGP
        row.P1 = drdP1.SelectedValue
        row.P2 = drdP2.SelectedValue
        row.P3 = drdP3.SelectedValue
        row.P4 = drdP4.SelectedValue
        row.P5 = drdP5.SelectedValue
        row.P6 = drdP6.SelectedValue
        row.P7 = drdP7.SelectedValue
        row.P8 = drdP8.SelectedValue
        row.Pole = drdPole.SelectedValue
        row.Lap = drdLap.SelectedValue
        row.Team = drdTeam.SelectedValue
        row.Dt = Date.Now()
        table.Rows.Add(row)
        ta.Update(table)
        Util.LogAccess(geraStringLog)
        Response.Redirect("Home.aspx")
    End Sub

    Protected Sub VerificaHoraLimite()
        Dim ta As DataSet1TableAdapters.GPTableAdapter = New DataSet1TableAdapters.GPTableAdapter
        Dim table As DataSet1.GPDataTable
        table = ta.GetDataByIdGP(IdGP)
        Dim horaTreino As Date = table.Rows(0).Item("DtTreino")
        Dim horaLimite As Date = horaTreino
        Dim horaLimiteBrasilia As Date = horaLimite.ToLocalTime
        Response.Write("<font style='color:red'>HORA LIMITE EH " + horaLimiteBrasilia + " Brasilia</font>")
    End Sub

    Private Function geraStringLog() As String
        Dim str = Session("Login") + " palpitou no GP " + IdGP.ToString + " : " + _
                  "P1: " + drdP1.SelectedItem.Text + " # " + _
                  "P2: " + drdP2.SelectedItem.Text + " # " + _
                  "P3: " + drdP3.SelectedItem.Text + " # " + _
                  "P4: " + drdP4.SelectedItem.Text + " # " + _
                  "P5: " + drdP5.SelectedItem.Text + " # " + _
                  "P6: " + drdP6.SelectedItem.Text + " # " + _
                  "P7: " + drdP7.SelectedItem.Text + " # " + _
                  "P8: " + drdP8.SelectedItem.Text + " # " + _
                  "Pole: " + drdPole.SelectedItem.Text + " # " + _
                  "Lap: " + drdLap.SelectedItem.Text + " # " + _
                  "Team: " + drdTeam.SelectedItem.Text
        Return str
    End Function

End Class